package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.common.persistence.model.TNotice;
import com.stylefeng.guns.modular.system.service.ITNoticeService;

/**
 * 短信语音历史纪录控制器
 *
 * @author fengshuonan
 * @Date 2018-05-05 12:13:10
 */
@Controller
@RequestMapping("/tNotice")
public class TNoticeController extends BaseController {

    private String PREFIX = "/system/tNotice/";

    @Autowired
    private ITNoticeService tNoticeService;

    /**
     * 跳转到短信语音历史纪录首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tNotice.html";
    }

    /**
     * 跳转到添加短信语音历史纪录
     */
    @RequestMapping("/tNotice_add")
    public String tNoticeAdd() {
        return PREFIX + "tNotice_add.html";
    }

    /**
     * 跳转到修改短信语音历史纪录
     */
    @RequestMapping("/tNotice_update/{tNoticeId}")
    public String tNoticeUpdate(@PathVariable Integer tNoticeId, Model model) {
        TNotice tNotice = tNoticeService.selectById(tNoticeId);
        model.addAttribute("item",tNotice);
        LogObjectHolder.me().set(tNotice);
        return PREFIX + "tNotice_edit.html";
    }

    /**
     * 获取短信语音历史纪录列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return tNoticeService.selectList(null);
    }

    /**
     * 新增短信语音历史纪录
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TNotice tNotice) {
        tNoticeService.insert(tNotice);
        return super.SUCCESS_TIP;
    }

    /**
     * 删除短信语音历史纪录
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer tNoticeId) {
        tNoticeService.deleteById(tNoticeId);
        return SUCCESS_TIP;
    }

    /**
     * 修改短信语音历史纪录
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TNotice tNotice) {
        tNoticeService.updateById(tNotice);
        return super.SUCCESS_TIP;
    }

    /**
     * 短信语音历史纪录详情
     */
    @RequestMapping(value = "/detail/{tNoticeId}")
    @ResponseBody
    public Object detail(@PathVariable("tNoticeId") Integer tNoticeId) {
        return tNoticeService.selectById(tNoticeId);
    }
}
